/*
 * @Author: cmd
 * @we_chat: cmd_develop
 * @LastEditors: cmd
 * @Description: 
 * @Date: 2019-02-21 15:26:00
 * @LastEditTime: 2019-03-14 11:30:57
 */

export default class utils{
   /**
     * 随机一个整数数字
     * @param min 从min开始
     * @param max 到max结束
     * @returns {*}
     */
    getRandom(min:number, max:number) {
        if (isNaN(min) || isNaN(max))return 0;
        if (min >= max) return min;
        var temp = (Math.random() * (max - min + 1) ) + min ;
        temp = Math.floor(temp);
        if(temp == max +1)
        {
            return max;
        }
        else
        {
            return temp;
        }
    }

    /**
     * 讲数字number转化成string
     * @param number 数字
    */
    string_number(number:number){
        var number_string = '';
        if(number >= 10000)
        {
            number_string = String((number/10000).toFixed(2))+'万';
        }
        else
        {
            number_string = String(number);
        }
        return number_string;
    }

    /**
     * 将秒时间转换为 03:15这种格式
     * @param time 
     */
    clock_convert(time:number){        
        let minus:String = ('00' + String(Math.floor(Number(time) / 60))).slice(-2);
        let second:String = ('00' + String(Number(time) % 60)).slice(-2);
        let clock_string = [];
        clock_string[0] = minus;
        clock_string[1] = second;
        return clock_string;        
    }

    /**
     * 将json数据转化成formdata
     * @param json 
    */
    json_to_formdata(json:object){
        let form = new FormData();   
        for(let key in json)
        {
            form.append(key,json[key])
        }
        return form;
    }
    

}
